package com.study.aop.theory.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author: chenhs
 * @date: Created in 16:35 2019/12/8
 **/
@Aspect
@Component
public class TimeConsumingStatisticsAspect {

    /**
     * Aspectj 表达式（Spring中一种古老的实现方式）
     */
    @Around("execution(* com.study.aop.theory.service.*.*(..))")
    public Object methodTimeConsumingStatistics(ProceedingJoinPoint pjp) throws Throwable {
        long stime = System.currentTimeMillis();
        Object ret = pjp.proceed();
        long useTime = System.currentTimeMillis() - stime;
        System.out.println("记录：" + pjp.getTarget() + "." + pjp.getSignature() + " 耗时：" + (useTime / 1000) + "秒");

        return ret;
    }

}
